#!/usr/bin/env python3
"""
简化的视频转码系统启动脚本
"""

import sys
import os
from pathlib import Path

# 添加src目录到Python路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root / "src"))

def check_dependencies():
    """检查依赖是否安装"""
    # 包名到导入名的映射
    package_mapping = {
        "PyQt6": "PyQt6",
        "opencv-python": "cv2",  # opencv-python包导入名为cv2
        "av": "av",
        "numpy": "numpy",
        "psutil": "psutil",
        "py-cpuinfo": "cpuinfo",  # py-cpuinfo包导入名为cpuinfo
        "GPUtil": "GPUtil",
        "qasync": "qasync",
    }
    
    missing_packages = []
    
    for package_name, import_name in package_mapping.items():
        try:
            __import__(import_name)
        except ImportError:
            missing_packages.append(package_name)
    
    if missing_packages:
        print("缺少必要的依赖包:")
        for package in missing_packages:
            print(f"  - {package}")
        print("\n请运行以下命令安装依赖:")
        print("pip install -r requirements.txt")
        return False
    
    return True

def main():
    """主启动函数"""
    print("🚀 启动视频转码系统...")
    
    # 检查依赖
    if not check_dependencies():
        sys.exit(1)
    
    # 导入主程序
    try:
        from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
        from PyQt6.QtCore import Qt
        
        # 创建Qt应用
        app = QApplication(sys.argv)
        app.setApplicationName("视频转码系统")
        app.setApplicationVersion("0.1.0")
        
        # 创建主窗口
        main_window = QMainWindow()
        main_window.setWindowTitle("视频转码系统 - 开发中")
        main_window.setGeometry(100, 100, 800, 600)
        
        # 添加欢迎标签
        welcome_label = QLabel("🎉 视频转码系统启动成功！\n\n"
                              "✅ 依赖检查通过\n"
                              "✅ PyQt6环境正常\n"
                              "✅ 系统准备就绪\n\n"
                              "正在加载完整功能...")
        welcome_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        welcome_label.setStyleSheet("font-size: 16px; font-family: Arial;")
        
        main_window.setCentralWidget(welcome_label)
        main_window.show()
        
        print("✅ 系统启动成功！")
        print("✅ 依赖检查通过")
        print("✅ PyQt6环境正常")
        print("✅ 准备开发完整功能")
        
        # 启动事件循环
        sys.exit(app.exec())
        
    except Exception as e:
        print(f"启动失败: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)

if __name__ == "__main__":
    main()